/**
 * 
 */
package com.base.myproject.client.busi.b2c.b2cgcodeattr;

import com.base.myproject.client.busi.b2c.ProdectDesc;
import com.base.myproject.client.tools.SendServlet;
import com.base.myproject.client.tools.XML;
import com.google.gwt.core.client.GWT;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;

/**
 * @author zgw
 *2009-8-5 上午07:28:25
 * javazgw@gmail.com
 */
public class AttrFactory {
	
	/**
	 * 规定好属性，通过对该商品大类gcode
	 */
	
//	final static int B2CGCODEATTR =1;
	final static int DEATAILDESC =2;
	final static int IMAGEGROUP =4;
	
	String b2cgcode	=null;
	ProdectDesc p ;
	public  AttrFactory(String b2cgcode)
	{
		this.b2cgcode = b2cgcode;
		p = new ProdectDesc(b2cgcode);
		
	}
	public String getB2cgcode() {
		return b2cgcode;
	}
	public void setB2cgcode(String b2cgcode) {
		this.b2cgcode = b2cgcode;
	}
	public void initAttrShow()
	{
		if(b2cgcode ==null)
			return;
	//	String sql = "select attrshow from gcode where exists (select * from b2cgcode where b2cgcode.gcode = gcode.gcode and b2cgcode.b2cgcode ='"+b2cgcode+"' ) ";
		String sql ="select b2cgcode,b2cgname,b.gcode,b.gname,mainimagepath,detailimageidx,recommend,adddate,price,discountprice,attrshow ,c.treecode,c.treename from (select * from b2cgcode)as a left join  ( select * from gcode ) as b on a.gcode = b.gcode left join (select * from b2cgcodetree)as c on a.treecode = c.treecode where a.b2cgcode = '"+b2cgcode+"'";
		String attrshow = "0";
		SendServlet ss = new SendServlet();
		
		String datawinstr = ss.getStringx("/"+GWT.getModuleName()+"/BaseServlet",
				"Action=getdatasql&sql=" + sql + "");
		Document doc = XMLParser.parse((String) datawinstr);

		NodeList list = doc.getElementsByTagName("record");

		for (int i = 0; i < list.getLength(); i++) {
			NodeList recordlist = list.item(i).getChildNodes();

			Node node = list.item(i);
			Element elem = (Element) node;


			attrshow = XML.getValue(elem, "attrshow");
			p.setDiscountprice(XML.getValue(elem, "discountprice"));
			p.setGcode(XML.getValue(elem, "gcode"));
			p.setGname(XML.getValue(elem, "gname"));
			p.setMainimagepath(XML.getValue(elem, "mainimagepath"));
			p.setName(XML.getValue(elem, "b2cgname"));
			p.setPrice(XML.getValue(elem, "price"));
			p.setTreecode(XML.getValue(elem, "treecode"));
			p.setTreename(XML.getValue(elem, "treename"));
			
		}
		attrshow=(attrshow==null?"0":attrshow);
		
		int attrshowint = Integer.parseInt(attrshow);
		if((attrshowint & DEATAILDESC )== DEATAILDESC )
		{
			DetailDesc detaildesc = new DetailDesc();
			p.put("detaildesc", detaildesc);
		}
		
		if((attrshowint & IMAGEGROUP )== IMAGEGROUP )
		{
			ImageGroup ii = new ImageGroup();
			p.put("imagegroup", ii);
		}
		System.out.println("p===="+p);
	
	}
	/**
	 * 显示的属性
	 * @return
	 */
	public ProdectDesc getP() {
		return p;
	}
	public void setP(ProdectDesc p) {
		this.p = p;
	}
	
}
